package com.clay.appointment.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * @author Yeung Wah
 * @since 2021/6/4
 */
@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfig {
    /**
     * 文档参数配置
     */
    @Value("${swagger.title}")
    public String title;
    @Value("${swagger.description}")
    public String description;
    @Value("${swagger.version}")
    public String version;
    @Value("${swagger.contactName}")
    public String contactName;
    @Value("${swagger.contactUrl}")
    public String contactUrl;
    @Value("${swagger.contactEmail}")
    public String contactEmail;

    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title(title)
                        .description(description)
                        .termsOfServiceUrl(contactUrl)
                        .contact(new Contact(contactName, contactUrl, contactEmail))
                        .version(version)
                        .build())
                .select()
                .apis(RequestHandlerSelectors.basePackage(Constants.BASE_PACKAGE))
                .paths(PathSelectors.any())
                .build();
    }
}